﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModelLibrary;
using System.Text;

namespace WebC
{
    public partial class DevTrashProcess : clsBaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Ajax.Utility.RegisterTypeForAjax(typeof(DevTrashProcess));
            if (!IsPostBack)
            {
                loadInfo();
            }
        }

        public string sFileName = GlobleClass.UpFileType.DevTrashfile.ToString(); //"DevMovefile";

        #region 载入信息

        public void loadInfo()
        {
            BuyDevice buy = null;
            string sModelName = "";
            DeviceInfo deviceinfo = new DeviceInfo();
            DataSet ds = null;
            try
            {
                buy = new BuyDevice();
                //inniDdlData(ddlPayWay,buy.getEnumDdl(2));
                if (m_Id == 0)
                {
                    if (!checkModelRightById(123, ref sModelName, (clsBaseLib)buy))
                    {
                        errorUrl(string.Format("你没有“{0}”的权限,请与管理员联系！", sModelName));
                        return;
                    }
                }
                else
                {
                    //if (Convert.ToInt32(Request["check"]) != 1)
                    //{
                        if (Convert.ToInt32(Request["noedit"]) == 1)
                        {
                            if (!checkModelRightById(122, ref sModelName, (clsBaseLib)buy))
                            {
                                errorUrl(sModelName);
                                return;
                            }
                        }
                        else
                        {
                            if (!checkModelRightById(125, ref sModelName, (clsBaseLib)buy))
                            {
                                errorUrl(sModelName);
                                return;
                            }
                        }
                    //}
                    //else
                    //{
                    //    tblCheck.EnableViewState = true;
                    //    tblEdit.EnableViewState = false;
                    //}
                        ds = deviceinfo.getTrashNoteInfoById(m_Id);
                    //hdselect.Value = buy.getContractSelectIds(m_Id);
                }
                sModelFullName = sModelName;

            }
            catch (Exception e)
            {
                errorUrl(Convert.ToString(e));
            }
            finally
            {
                if (buy != null)
                {
                    buy.Dispose();
                }
                if (deviceinfo != null)
                {
                    deviceinfo.Dispose();
                }
            }
            if (m_Id > 0)
            {
                if (ds != null)
                {
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count == 1)
                    {
                        hidDevID.Value = dt.Rows[0]["DevID"].ToString().Trim();
                        dProcessType.SelectedValue = Convert.ToString(dt.Rows[0]["ProcessType"]);
                        txtTrashCode.Text = Convert.ToString(dt.Rows[0]["TrashAppCode"]);
                        txtDevCode.Text = Convert.ToString(dt.Rows[0]["DeviceCode"]);
                        txtProcessDate.Text = Convert.ToString(dt.Rows[0]["dProcessTime"]);
                        txtDevName.Text = Convert.ToString(dt.Rows[0]["DeviceName"]);
                        txtProcessMan.Text = Convert.ToString(dt.Rows[0]["ProcessEmploy"]);
                        txtCommon.Text = Convert.ToString(dt.Rows[0]["ProcessComment"]);
                    }
                }
            }
        }

        #endregion

        int m_Id
        {
            get
            {
                return Convert.ToInt32(Request["id"]);
            }
        }
        int m_DevId
        {
            get
            {
                return Convert.ToInt32(Request["devid"]);
            }
        }

        #region 获得设备

        [Ajax.AjaxMethod]
        public DataTable getSelectDeviceInfo(string sIds)
        {
            BuyDevice buy = null;
            DataTable dt = null;
            try
            {
                buy = new BuyDevice();
                dt = buy.getResultDeviceInfo(sIds);
            }
            catch
            {
                dt = null;
            }
            finally
            {
                if (buy != null)
                {
                    buy.Dispose();
                }
            }
            return dt;
        }

        #endregion

        #region 保存信息

        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public bool saveData(int cid, int devid, string cdate, string processtype, string processman, string processcomment,string selectids)
        {
            //BuyDevice buy = null;
            DeviceInfo deviceinfo = new DeviceInfo();
            bool bResult = false;
            cdate = cdate.Replace("'", "''");
            processtype = processtype.Replace("'", "''");
            processman = processman.Replace("'", "''");
            processcomment = processcomment.Replace("'", "''");
            try
            {
                //buy = new BuyDevice();

                //for (int i = 0; i < sDevices.Length; i++)
                //{
                //    sDevices[i] = sDevices[i].Replace("'", "''");
                //}
                bResult = deviceinfo.setTrashNoteInfo(cid, devid, cdate, processtype, processman, processcomment, selectids);
            }
            catch
            {
                bResult = false;
            }
            finally
            {
                if (deviceinfo != null)
                {
                    deviceinfo.Dispose();
                }
            }
            return bResult;
        }

        #endregion
    }
}